// ignore_for_file: avoid_print

import 'dart:ui';
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'app_route.dart';
import 'app_root.dart';
import 'page_login.dart';
import 'login/login_main.dart';
import 'app_default.dart';
import 'app_channel.dart';

// 默认APP界面
@pragma('vm:entry-point')
void main() {
  print("====== main ======");
  runApp(const MyApp());
}

// 指定界面
@pragma('vm:entry-point')
void twoMain() {
  print("====== twoMain ======");
  
  String router = window.defaultRouteName;
  print("设置的 window.defaultRouteName :$router");
  // 页面尺寸
  print("页面尺寸: ${window.physicalSize.height}");
  print("页面尺寸: ${window.physicalSize.width}");
  runApp(_routeRoot());
  // return runApp(FlutterApp());
  // 修改状态栏
  // ignore: prefer_const_constructors
  SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    statusBarBrightness: Brightness.light,
    statusBarIconBrightness: Brightness.dark,
    systemNavigationBarColor: Colors.transparent,
    systemNavigationBarIconBrightness: Brightness.dark
  );
  SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}

@pragma('vm:entry-point')
void threeMain() {
  print("====== threeMain ======");
}

@pragma('vm:entry-point')
void loginBook() {
  // 捕获 invokeMethod 异常信息
  // runApp(getRouter(window.defaultRouteName));
  runZonedGuarded(() {
    runApp(getRouter(window.defaultRouteName));
  }, (Object errorObject, StackTrace stackTrace) {
    print("========flutter=========");
    print(errorObject);
    print("=======================");
  });
}

Widget _routeRoot() {
  return Container(
    child: _route(window.defaultRouteName),
  );
}

// 根据入口传参路由, 跳转不同界面
Widget _route(String router) {
  switch (router) {
    case "root":
      return const FlutterRootApp();
    case "channel":
      return channelMain();
    case "default":
      return FlutterApp();
    case "route":
      return RouteApp();
    case "login":
      return const LoginPageStatic();
    default:
      return FlutterApp();
  }
}
